<template>
  <base-option :selected="selected" :field-config="fieldConfig" :form-config="formConfig">
    <template #default="{ hideOptions }">
      <el-form-item v-if="fieldConfig.defaultValue !== undefined && hideOptions('defaultValue')" label="默认值">
        <el-input v-model="fieldConfig.defaultValue" type="text" :maxlength="fieldConfig.maxlength" />
      </el-form-item>

      <el-form-item v-if="fieldConfig.maxlength !== undefined && hideOptions('maxlength')" label="长度限制">
        <el-input v-model="fieldConfig.maxlength" placeholder="最大字符长度">
          <template #append>个字符</template>
        </el-input>
      </el-form-item>

      <el-form-item v-show="fieldConfig.selectSumName !== undefined" label="金额组件">
        <template #label>
          <div>
            金额组件
            <el-popover
              placement="top-start"
              title=""
              :width="200"
              trigger="hover"
              content="配套金额组件使用，请选择金额组件。"
            >
              <template #reference>
                <el-icon><QuestionFilled /></el-icon>
              </template>
            </el-popover>
          </div>
        </template>
        <el-select v-model="fieldConfig.selectSumName" placeholder="请选择金额组件">
          <el-option
            v-for="item in selectList"
            :key="item.options.name"
            :label="item.options.label"
            :value="item.options.name"
          />
        </el-select>
      </el-form-item>
    </template>
  </base-option>
</template>

<script setup>
import { toRefs, computed } from 'vue'
import baseOption from './base-option.vue'
import propsDefinition from './props'
const props = defineProps(propsDefinition)
const { selected, widgetList, fieldConfig, formConfig } = toRefs(props)

const selectList = computed(() => {
  return widgetList.value.filter((m) => m.type === 'amount')
})
</script>
